Skip to content

feat: sort results by average frequency across all dictionaries - #2460

Open
wtestcase wants to merge 1 commit into
yomidevs:masterfrom
wtestcase:feat/sort-by-average-frequency
Open

feat: sort results by average frequency across all dictionaries#2460
wtestcase wants to merge 1 commit into
yomidevs:masterfrom
wtestcase:feat/sort-by-average-frequency

Conversation

@wtestcase

Copy link
Copy Markdown

DISCLAIMER: I've been wanting this feature for a while too, so I quickly 100% vibecoded this.

Summary

Closes #1957.

Yomitan can already display a per-entry harmonic average frequency across all installed frequency dictionaries, but the "Frequency sorting dictionary" setting could only sort by a single dictionary. This meant results could be ordered in a way that contradicts the average shown in the popup (see the example in the issue, where an entry present in only one dictionary outranks an entry with a lower average).

This PR adds an Average (all dictionaries) option to that setting. When selected, results are sorted by the harmonic average frequency across every installed frequency dictionary.

Details

  • Reuses the exact display value. Sorting calls the same getFrequencyHarmonic(entry, headwordIndex, null) used to render the "Average" frequency row, so the sort order always agrees with the number the user sees (rank-based and occurrence-based dictionaries are blended identically to the display).
  • Representation. The choice is stored in the existing general.sortFrequencyDictionary setting using a NUL-prefixed sentinel value, so there's no schema change / options migration and no possibility of colliding with a real dictionary title.
  • Metadata loading. In simple lookup mode the translator normally loads only the selected sort dictionary's metadata; when Average is selected it now loads all enabled frequency dictionaries (as useAllFrequencyDictionaries already does), since averaging requires them.
  • Ascending/descending still applies (Rank-based vs Occurrence-based). The Auto order-detection button is intentionally inert for Average, since there's no single dictionary to probe.
  • The option only appears when at least one frequency dictionary is installed.

Testing

  • Added test/translator-frequency-sort.test.js covering the new harmonic ordering: cross-dictionary averaging, ascending vs descending, one-value-per-dictionary de-duplication, and the no-frequency-data fallback.
  • Manually verified in Chrome: the new option appears, and popup ordering matches the displayed "Average" values.
  • npm run test:js, test:ts, existing translator golden tests (test/dictionary-data.test.js), and options-util tests pass.

…ries

Adds an "Average (all dictionaries)" option to the frequency sorting
dictionary setting. When selected, results are ordered by the harmonic
average frequency across every installed frequency dictionary, using the
exact same value shown in the "Average" frequency display.

Closes yomidevs#1957

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wtestcase
wtestcase requested a review from a team as a code owner July 10, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using "average" frequency as "Frequency sorting dictionary"

1 participant